package com.jgj.zxkj.lookandcheckjggroupinfo.record.detail;

import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.GridLayoutManager;
import android.util.SparseArray;

import com.allen.library.CommonTextView;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.jgj.zxkj.lookandcheckjggroupinfo.R;
import com.sa.all_cui.mix_ui.recycler.ItemType;
import com.sa.all_cui.mix_ui.recycler.MultipleItemEntity;
import com.sa.all_cui.mix_ui.recycler.MultipleViewHolder;

import java.util.List;

/**
 * Created by all-cui on 2017/11/3.
 */

@SuppressWarnings("WeakerAccess")
public class CheckDetailAdapter extends BaseMultiItemQuickAdapter<MultipleItemEntity, MultipleViewHolder>
        implements BaseQuickAdapter.SpanSizeLookup {

    public CheckDetailAdapter(@Nullable List<MultipleItemEntity> data) {
        super(data);
        init();
    }

    private void init() {
        //设置不同的item布局
        addItemType(ItemType.TEXT, R.layout.item_multiple_text);
        addItemType(ItemType.TEXT_DOUBLE, R.layout.item_multiple_text);
        setSpanSizeLookup(this);
        openLoadAnimation();
        //多次执行动画
        isFirstOnly(false);
    }

    @Override
    protected void convert(MultipleViewHolder holder, MultipleItemEntity item) {
        CommonTextView tv;
        switch (holder.getItemViewType()) {
            case ItemType.TEXT:
                tv = holder.getView(R.id.ctv_multiple_text);
                final String value = item.getField(ItemType.TEXT);
                tv.setLeftTextString(value);
                tv.setLeftDrawableLeft(ContextCompat.getDrawable(tv.getContext(), R.drawable.ic_back));
                break;
            case ItemType.TEXT_DOUBLE:
                tv = holder.getView(R.id.ctv_multiple_text);
                final SparseArray<String> values = item.getField(ItemType.TEXT_DOUBLE);
                tv.setLeftTextString(values.get(0));
                tv.setRightTextString(values.get(1));
                break;
            default:
                break;
        }
    }

    @Override
    public int getSpanSize(GridLayoutManager gridLayoutManager, int position) {
        return 1;
    }
}
